package com.haiheng.library_base.view.webview

import android.webkit.JavascriptInterface
import com.haiheng.library.log.LogUtils
import com.haiheng.videodoorbell.widget.webview.IX5WebPageView

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2022/12/19 0019
 * @Version: 1.0
 */
class JSInterface @JvmOverloads constructor(
    ix5WebPageView: IX5WebPageView
) {


    val mIWebPageView: IX5WebPageView

    init {
        this.mIWebPageView = ix5WebPageView
    }

    //
//    @JavascriptInterface
//    fun openCamera(){
//        LogUtils.e("打开相机")
//        openCamera()
//    }
    @JavascriptInterface
    fun onJsFunctionCalled(funName: String) {
        LogUtils.e("打开:$funName")
        if (mIWebPageView != null){
            mIWebPageView.onJsFunctionCalled(funName,null,null)
        }
    }
    @JavascriptInterface
    fun saveH5Info(key: String,value:String) {
        LogUtils.e("h5保存信息key :$key  valse:$value")
        if (mIWebPageView != null){
            mIWebPageView.onJsFunctionCalled("saveH5Info",key,value)
        }
    }

    @JavascriptInterface
    fun getH5SavaInfo(key:String){
        if (mIWebPageView != null){
            mIWebPageView.onJsFunctionCalled("getH5SavaInfo",key,null)
        }
    }
}